﻿namespace VSTOTestProject
{
    using System;
    using System.CodeDom.Compiler;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Text.RegularExpressions;
    using System.Windows.Input;
    using System.Windows.Forms;
    using Microsoft.VisualStudio.TestTools.UITest.Extension;
    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UITesting.WinControls;
    using Microsoft.VisualStudio.TestTools.UITesting.WpfControls;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using Keyboard = Microsoft.VisualStudio.TestTools.UITesting.Keyboard;
    using Mouse = Microsoft.VisualStudio.TestTools.UITesting.Mouse;
    using MouseButtons = System.Windows.Forms.MouseButtons;
    using Word = Microsoft.Office.Interop.Word;
    
    
    public partial class UIMap_VSTO
    {
        /// <summary>
        /// Focus on the document.
        /// </summary>
        public void FocusDoc()
        {
            #region Variable Declarations
            WinTitleBar uIItemTitleBar = this.UIDocumentWindow.UIItemWindow.UIRibbonPropertyPage.UIItemTitleBar;
            #endregion            

            try
            {                
                Assert.AreEqual<bool>(true, uIItemTitleBar.WaitForControlExist());
                Mouse.Click(uIItemTitleBar);
            }
            catch (Exception ex)
            {
                Assert.Fail("Exception in UIMap_VSTO.FocusDoc: " + ex.ToString());
            }
        }

        /// <summary>
        /// Creates a HyperLink in the document.
        /// </summary>
        public void CreateHyperLink(string linkAddress)
        {
            #region Variable Declarations
            WinTabPage uIInsertTabPage = this.UIDocumentWindow.UIItemWindow.UIRibbonClient.UITabPage;
            WinButton uIHyperlinkButton = this.UIDocumentWindow.UIItemWindow.UIToolGroup.UIWinButton;
            WinEdit uIAddressEdit = this.UIInsertHyperlinkWindow.UIInsertHyperlinkDialog.UIAddressEdit;
            WinButton uIOKButton = this.UIInsertHyperlinkWindow.UIInsertHyperlinkDialog.UIOKButton;
            #endregion           

            try
            {
                uIInsertTabPage.WaitForControlReady(1000);

                // Click 'Insert' tab twice to ensure the tab functionalities are displayed
                Mouse.Click(uIInsertTabPage);
                Mouse.Click(uIInsertTabPage);                

                // Click 'Hyperlink...' button
                Mouse.Click(uIHyperlinkButton);                
                
                // Set link address in 'Address:' text box
                uIAddressEdit.Text = linkAddress;                

                // Click 'OK' button
                Mouse.Click(uIOKButton);
            }
            catch (Exception ex)
            {
                Assert.Fail("Exception in UIMap_VSTO.FocusDoc: " + ex.ToString());
            }

        }

        public void ClickDemoAddinButton()
        {
            #region Variable Declarations
            WinTabPage uIAddinTabPage = this.UIDocumentWindow.UIItemWindow.UIRibbonClient.UITabPage;
            WinButton uIDemoAddinButton = this.UIDocumentWindow.UIItemWindow.UIToolGroup.UIWinButton;
            WinButton uIOKButton = this.UIDemoAddinWindow.UIOKButton;
            #endregion
            try
            {
                uIAddinTabPage.WaitForControlReady(1000);
                // Click 'Insert' tab twice to ensure the tab functionalities are displayed
                Mouse.Click(uIAddinTabPage);
                Mouse.Click(uIAddinTabPage);

                // Click 'Hello World Button in Demo Addin' button
                Mouse.Click(uIDemoAddinButton);
                Mouse.Click(uIOKButton);
            }
            catch (Exception ex)
            {
                Assert.Fail("Exception in UIMap_VSTO.ClickDemo: " + ex.ToString());
            }
        }


    }
}
